package com.jingan.nursinghome.regulatory.data;

import android.util.Log;

import com.jingan.nursinghome.regulatory.dialog.CreateMicrometerTableDailog;
import com.jingan.nursinghome.regulatory.dialog2.CreateMicrometerTableDailog2;
import com.jingan.nursinghome.regulatory.dialog3.CreateMicrometerTableDailog3;
import com.jingan.nursinghome.regulatory.http.Http;
import com.jingan.nursinghome.regulatory.model.Categories;
import com.jingan.nursinghome.regulatory.model.Jinlaoyuang;
import com.jingan.nursinghome.regulatory.model.Linkup;
import com.jingan.nursinghome.regulatory.model.Qfinfo;
import com.jingan.nursinghome.regulatory.model.TimuType;
import com.jingan.nursinghome.regulatory.model.Topic;
import com.jingan.nursinghome.regulatory.model.User;

import org.json.JSONArray;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cn.android.support.v7.lib.sin.crown.base.BaseApplication;
import cn.android.support.v7.lib.sin.crown.base.BaseListenner;
import cn.android.support.v7.lib.sin.crown.utils.AssetsUtils;
import cn.android.support.v7.lib.sin.crown.utils.CacheUtils;
import cn.android.support.v7.lib.sin.crown.utils.JSONObjectUtils;
import cn.android.support.v7.lib.sin.crown.utils.TimeUtils;

/**
 * 数据表
 * Created by 彭治铭 on 2017/9/25.
 */

public class MicrometerTable {
    private MicrometerTable() {
        topics = new ArrayList<>();
        user = new User();
    }

    private static MicrometerTable micrometerTable;

    public static MicrometerTable getInstance() {
        if (micrometerTable == null) {
            micrometerTable = new MicrometerTable();
        }
        return micrometerTable;
    }

    User user;//用户数据

    //用户标志
    public String getUserMark() {
        return "userMark:" + user.getPhone();
    }

    public User getUser() {
        return user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<Categories> categories = new ArrayList<>();

    //数据类别标志=========================================================================================================================================================================================================================
    public String getCategoriesMark(String rid) {
        return "类别根据类型ID区分" + rid;
    }

    //获取题目类型
    public List<Categories> getCategories(String rid) {
        if (categories == null || categories.size() <= 0) {
            Http.getInstance().getCategory(rid);
        }
        return categories;
    }

    public List<Topic> topicsAll = new ArrayList<>();//千分表所有数据

    //千分表总数据标志=========================================================================================================================================================================================================================
    public String getTopicsALLMark() {
        return "总数据不区分用户" + ":topicsALL2";
    }

    public List<Topic> getTopicsAll() {
        if (topicsAll == null || topicsAll.size() <= 0) {
            Http.getInstance().getQian();
        }
        return topicsAll;
    }

    public List<Topic> topics;//千分表数据

    //千分表数据标志=========================================================================================================================================================================================================================
    public String getTopicsMark(String rid, String jlyName) {
        if (rid != null && jlyName != null) {
            return getUserMark() + ":topics13" + TimeUtils.getInstance().getAbsoluteTime("yyyy-MM-DD") + rid + jlyName;
        }
        return getUserMark() + ":topics13";
    }

    //一定要等到用户登录之后，再初始化数据。不然无法获取用户标识
    public List<Topic> getTopics(String rid, String jlyName) {

//        if (topics.size() <= 0) {
//            JSONArray jsonArray = CacheUtils.getInstance().getAsJSONArray(getTopicsMark(rid, jlyName));//获取本地缓存
//            if (jsonArray != null) {
//                //Log.e("test", "千分表缓存:\t类型:\t"+rid+"\t经脑院:\t"+jlyName);
//                topics = JSONObjectUtils.getInstance().getArrayList(jsonArray, Topic.class);
//            }
//            else {
//                //Log.e("test", "新数据:	"+rid+"\t经脑院:\t"+jlyName);
//                int count = 1;
//                topics.clear();
//                for (int i = 0; i < getTopicsAll().size(); i++) {
//                    if (getTopicsAll().get(i).getRid().trim().equals(rid)) {
//                        Topic topic = new Topic();
//                        topic.Copy(getTopicsAll().get(i));
//                        topic.setCount(count + "");
//                        count++;
//                        topics.add(topic);
//                    }
//                }
//            }
//        }

        if (topics.size() <= 0) {
            List<Topic> cTopics = null;
            JSONArray jsonArray = CacheUtils.getInstance().getAsJSONArray(getTopicsMark(rid, jlyName));//获取本地缓存
            if (jsonArray != null) {
                //Log.e("test", "千分表缓存:\t类型:\t"+rid+"\t经脑院:\t"+jlyName);
                cTopics = JSONObjectUtils.getInstance().getArrayList(jsonArray, Topic.class);
            }

            topicsHostoryQF = getHostoryQFTopics();

            int count = 1;
            topics.clear();
            //Log.e("test","缓存数量:\t"+cTopics.size());
            for (int i = 0; i < getTopicsAll().size(); i++) {
                if (getTopicsAll().get(i).getRid().trim().equals(rid)) {
                    Topic topic = new Topic();
                    topic.Copy(getTopicsAll().get(i));
                    topic.setCount(count + "");

                    if (cTopics != null && cTopics.size() > i) {
                        //Log.e("test","进来了");
                        //缓存里面获取
                        for (int k = 0; k < cTopics.size(); k++) {
                            if (topic.getId().trim().equals(cTopics.get(k).getId().trim()) || topic.getQuestion().trim().equals(cTopics.get(k).getQuestion().trim())) {
                                topic.setZhengai(cTopics.get(k).getZhengai());//整改
                                topic.setRemark(cTopics.get(k).getRemark());//备注
                                topic.setCscore(cTopics.get(k).getCscore());//当前分数
                            }
                        }

                    }

                    boolean b = false;//是否为历史整改的题目
                    if (topicsHostoryQF != null && topicsHostoryQF.size() > 0) {
                        //Log.e("test", "进来了");
                        for (int j = 0; j < topicsHostoryQF.size(); j++) {
                            //Log.e("test", "id:\t" + topic.getId().trim() + "\tid:\t" + topicsHostoryQF.get(j).getId().trim());
                            if (topic.getId().trim().equals(topicsHostoryQF.get(j).getId().trim())) {
                                b = true;
                            }
                            if (topic.getQuestion().trim().equals(topicsHostoryQF.get(j).getQuestion().trim())) {
                                b = true;
                            }
                        }
                    }
                    if (!b) {
                        //千分表里的题目不包含历史整改的题目
                        count++;
                        topics.add(topic);
                    }
                }
            }
            if (topics.size() > 0) {
                //千分表表排序
                String title = "";
                int titleIndex = 1;//标题下标
                for (int i = 0; i < topics.size(); i++) {
                    if (i == 0) {
                        topics.get(i).setIndex("0");
                        topics.get(i).setTitleIndex(titleIndex + "");
                        titleIndex++;
                        title = topics.get(i).getTitle();
                    } else {
                        if (title.trim().equals(topics.get(i).getTitle().trim())) {
                            topics.get(i).setIndex("1");
                        } else {
                            topics.get(i).setIndex("0");
                            topics.get(i).setTitleIndex(titleIndex + "");
                            titleIndex++;
                            title = topics.get(i).getTitle();
                        }
                    }
                }
            }

        }

//        if (topics.size() <= 0) {
//            JSONArray jsonArray = CacheUtils.getInstance().getAsJSONArray(getTopicsMark());//获取本地缓存
//            if (jsonArray != null) {
//                topics = JSONObjectUtils.getInstance().getArrayList(jsonArray, Topic.class);
//            } else {
//                try {
//                    //本地缓存没有，则加载本地json文件
//                    String micrometer = UtilAssets.getInstance(BaseApplication.getInstance()).getStringFromAssets("micrometertable.json");
//                    jsonArray = new JSONArray(micrometer);
//                    int count = 1;
//                    int titleIndex = 0;
//                    for (int i = 0; i < jsonArray.length(); i++) {
//                        JSONObject jsonObject = jsonArray.getJSONObject(i);
//                        String category = jsonObject.get("category").toString();
//                        String data = jsonObject.getString("data");
//                        JSONArray datas = new JSONArray(data);
//                        for (int j = 0; j < datas.length(); j++) {
//                            titleIndex++;
//                            JSONObject jsonObject1 = datas.getJSONObject(j);
//                            String title = jsonObject1.getString("title");
//                            String tScore = jsonObject1.getString("tScore");
//                            String problem = jsonObject1.getString("problem");
//                            JSONArray problems = new JSONArray(problem);
//                            for (int k = 0; k < problems.length(); k++) {
//                                JSONObject jsonObject2 = problems.getJSONObject(k);
//                                String question = jsonObject2.getString("question");
//                                String maxScore = jsonObject2.getString("maxScore");
//                                String standard = jsonObject2.getString("standard");
//                                String focuson = "0";
//                                if (jsonObject2.has("focuson")) {
//                                    focuson = jsonObject2.getString("focuson");//是否为重点，1是为重点。其他的非重点
//                                }
//                                Topic topic = new Topic();
//                                topic.setCategory(category);
//                                topic.setTitle(title);
//                                topic.setCount(String.valueOf(count++));
//                                topic.setIndex(String.valueOf(k));
//                                topic.setQuestion(question);
//                                topic.setMaxScore(maxScore);
//                                topic.setTscore(tScore);
//                                topic.setStandard(standard);
//                                topic.setFocuson(focuson);
//                                topic.setTitleIndex(titleIndex + "");
//                                topics.add(topic);//添加到数组集合
//                            }
//                        }
//                    }
//                } catch (Exception e) {
//                    Log.e("test", "json数据解析异常:\t" + e.getMessage());
//                }
//            }
//        }
        return topics;
    }

    //缓存千分表
    public void saveTopics() {
        if (topics != null && topics.size() > 0) {

            CacheUtils.getInstance().put(getTopicsMark(CreateMicrometerTableDailog.rid, CreateMicrometerTableDailog.jlyName), JSONObjectUtils.getInstance().ArrayListToJSON(topics), 60 * 60 * 24);
            //Log.e("test","保存数量:\t"+topics.size());
        }
    }

    Map<String, List<Topic>> maps = new HashMap<>();

    //根据类别和题目大类获取题目
    public List<Topic> getCategoryTopics(String category, String rid) {
//        if (maps.containsKey(category + rid)) {
//            return maps.get(category + rid);
//        }
//        Log.e("test", "category：\t" + category + "\trid:\t" + rid);
        String categoryID = getCategorID(category, rid);
        List<Topic> categoryTopics = new ArrayList<>();
        for (int i = 0; i < getTopicsAll().size(); i++) {
            String c = getTopicsAll().get(i).getCategory().trim();//类别
            String r = getTopicsAll().get(i).getRid().trim();//大类
            String d = getTopicsAll().get(i).getCategoryID().trim();//id
//            Log.e("test", "c：\t" + c + "\tr:\t" + r);
            //if (category.trim().equals(c.trim()) && rid.trim().equals(r)) {

            if ((category.trim().equals(c.trim()) || categoryID.trim().equals(d)) && rid.trim().equals(r)) {

                boolean b = false;//是否为历史整改的题目
                if (topicsHostoryRC != null && topicsHostoryRC.size() > 0) {
                    //Log.e("test", "进来了");
                    for (int j = 0; j < topicsHostoryRC.size(); j++) {
                        //Log.e("test", "id:\t" + topic.getId().trim() + "\tid:\t" + topicsHostoryQF.get(j).getId().trim());
                        if (getTopicsAll().get(i).getId().trim().equals(topicsHostoryRC.get(j).getId().trim())) {
                            b = true;
                        }
                        if (getTopicsAll().get(i).getQuestion().trim().equals(topicsHostoryRC.get(j).getQuestion().trim())) {
                            b = true;
                        }
                    }
                }
                if (!b) {
                    //日常表里的题目不包含历史整改的题目
                    categoryTopics.add(getTopicsAll().get(i));
                }

//                categoryTopics.add(getTopicsAll().get(i));
            }
        }
//        maps.put(category + rid, categoryTopics);
        return categoryTopics;
    }

    public List<Topic> topicsHostoryQF = new ArrayList<>();//千分表历史整改数据
    public List<Topic> topicsHostoryRC = new ArrayList<>();//日常表历史整改数据

    //千分表历史整改数据标志
    public String getTopicsHostoryQFMark() {
        return "topicsHostoryQFMark" + CreateMicrometerTableDailog.jlyName + CreateMicrometerTableDailog.rid;
    }

    //日常表历史整改数据标志
    public String getTopicsHostoryRCMark() {
        return "topicsHostoryRCMark" + CreateMicrometerTableDailog2.jlyName + CreateMicrometerTableDailog2.rid;
    }

    //获取千分表的历史记录(再创建表的时候，获取。再提交之后。清空)
    public List<Topic> getHostoryQFTopics() {
        if (topicsHostoryQF == null || topicsHostoryQF.size() <= 0) {
//            final String hotoryMark = "千分表历史整改" + UtilTime.getInstance().getAbsoluteTime("yyyy-MM");//数据缓存一天
//            String url = "";
//            UtilHttp.getInstance().sendPost(url, null, new UtilHttp.RequestCallBack() {
//                @Override
//                public boolean onStart() {
//                    return false;
//                }
//
//                @Override
//                public void onSuccess(String result) {
//                    //缓存数据
//                    if (topicsHostoryQF != null && topicsHostoryQF.size() > 0) {
//                        CacheUtils.getInstance().put(hotoryMark, JSONObjectUtils.getInstance().ArrayListToJSON(topicsHostoryQF), 60 * 60 * 24);//数据缓存一天
//                    }
//                }
//
//                @Override
//                public void onFailure(String result) {
//                    Log.e("test", "获取千分表历史整改异常2:\t" + result);
//                    JSONArray jsonArray = CacheUtils.getInstance().getAsJSONArray(hotoryMark);//获取本地缓存
//                    if (jsonArray != null) {
//                        topicsHostoryQF = JSONObjectUtils.getInstance().getArrayList(jsonArray, Topic.class);
//                    }
//                }
//            });
            JSONArray jsonArray = CacheUtils.getInstance().getAsJSONArray(getTopicsHostoryQFMark());//获取本地缓存
            if (jsonArray != null) {
                topicsHostoryQF = JSONObjectUtils.getInstance().getArrayList(jsonArray, Topic.class);
            }
        }
        return topicsHostoryQF;
    }

    //缓存千分表历史整改记录
    public void saveHostoryQFTopics() {
        if (topics != null && topics.size() > 0) {
            topicsHostoryQF.clear();
            for (int i = 0; i < topics.size(); i++) {
                if (topics.get(i).getZhengai().trim().equals("2")) {//只保存计划整改的。
                    topicsHostoryQF.add(topics.get(i));
                }
            }
            CacheUtils.getInstance().put(getTopicsHostoryQFMark(), JSONObjectUtils.getInstance().ArrayListToJSON(topicsHostoryQF));
        }
    }

    //缓存日常表历史整改记录
    public void saveHostoryRCTopics() {
        if (topicsRc != null && topicsRc.size() > 0) {
            topicsHostoryRC.clear();
            for (int i = 0; i < topicsRc.size(); i++) {
                if (topicsRc.get(i).getZhengai().trim().equals("2")) {//只保存计划整改的。
                    topicsHostoryRC.add(topicsRc.get(i));
                }
            }
            CacheUtils.getInstance().put(getTopicsHostoryRCMark(), JSONObjectUtils.getInstance().ArrayListToJSON(topicsHostoryRC));
        }
    }

    //获取日常表的历史记录(再创建表的时候，获取。再提交之后。清空)
    public List<Topic> getHostoryRCTopics() {
        if (topicsHostoryRC == null || topicsHostoryRC.size() <= 0) {
//            final String hotoryMark = "日常表历史整改" + UtilTime.getInstance().getAbsoluteTime("yyyy-MM");//数据缓存一天
//            String url = "";
//            UtilHttp.getInstance().sendPost(url, null, new UtilHttp.RequestCallBack() {
//                @Override
//                public boolean onStart() {
//                    return false;
//                }
//
//                @Override
//                public void onSuccess(String result) {
//                    //缓存数据
//                    if (topicsHostoryRC != null && topicsHostoryRC.size() > 0) {
//                        CacheUtils.getInstance().put(hotoryMark, JSONObjectUtils.getInstance().ArrayListToJSON(topicsHostoryRC), 60 * 60 * 24);//数据缓存一天
//                    }
//                }
//
//                @Override
//                public void onFailure(String result) {
//                    Log.e("test", "获取日常表历史整改异常2:\t" + result);
//                    JSONArray jsonArray = CacheUtils.getInstance().getAsJSONArray(hotoryMark);//获取本地缓存
//                    if (jsonArray != null) {
//                        topicsHostoryRC = JSONObjectUtils.getInstance().getArrayList(jsonArray, Topic.class);
//                    }
//                }
//            });

            JSONArray jsonArray = CacheUtils.getInstance().getAsJSONArray(getTopicsHostoryRCMark());//获取本地缓存
            if (jsonArray != null) {
                topicsHostoryRC = JSONObjectUtils.getInstance().getArrayList(jsonArray, Topic.class);
            }
        }
        return topicsHostoryRC;
    }

    //日常表数据标志================================================================================================================================================================================================================
    public String getTopicsMarkRichang() {
        return getTopicsMark(null, null) + "日常表" + CreateMicrometerTableDailog2.jlyName + CreateMicrometerTableDailog2.rid;//千分表标志+日程表敬老院+题目类型 为标志。
    }

    public String richang;//保存题目题号(千分表总数据的题目序号)。多个之间用逗号","隔开。
    public List<String> richangS = new ArrayList<>();//日常表数据，直接调用即可

    //缓存日常表上一次的题目序号---标志
    public String getcacheRichanMark() {
        return "日常表题目序号" + CreateMicrometerTableDailog2.jlyName + CreateMicrometerTableDailog2.rid;
    }

    //获取日常表上一次的题目序号
    public String getcaceRichang() {
        return CacheUtils.getInstance().getAsString(getcacheRichanMark());
    }

    //缓存日常表上一次的题目序号
    public void caceRichang() {
        if (richang == null) {
            richang = CacheUtils.getInstance().getAsString(getTopicsMarkRichang());
        }
        if (richang != null) {
            CacheUtils.getInstance().put(getcacheRichanMark(), richang);
        }
        //Log.e("test","缓存:\t"+richang);
    }

    //获取和初始日常表数据。
    public List<String> getRichangIndex() {
        richang = CacheUtils.getInstance().getAsString(getTopicsMarkRichang());
        if (richang != null) {
            richangS.clear();
            String[] ss = richang.split(",");
            for (int i = 0; i < ss.length; i++) {
                //Log.e("test", "数组：\t" + ss[i]);
                richangS.add(ss[i]);
            }
        } else {
            richangS.clear();//清楚
        }
        return richangS;
    }

    //保存日常表数据
    public void saveRichangIndex() {
        if (richangS != null && richangS.size() > 0) {
            richang = null;
            for (int i = 0; i < richangS.size(); i++) {
                if (richang == null) {
                    richang = richangS.get(i).trim();
                } else {
                    richang = richang + "," + richangS.get(i).trim();
                }
            }
            if (richang != null) {
                CacheUtils.getInstance().put(getTopicsMarkRichang(), richang);
            }
        } else {
            CacheUtils.getInstance().remove(getTopicsMarkRichang());
        }
    }

    //判断
    public boolean panduan(String count) {
        return richangS.contains(count.trim());
    }

    //增
    public void addRiChange(String count) {
        if (!panduan(count)) {
            richangS.add(count.trim());
        }
    }

    //减
    public void jianRiChange(String count) {
        if (panduan(count)) {
            richangS.remove(count);
        }
    }

    List<Topic> topicsRc;//日常表答题数据

    //开始答题的时候。会数据清空。再获取。
    public void setTopicsRc(List<Topic> topicsRc) {
        this.topicsRc = topicsRc;
    }

    public List<Topic> getTopicsRc() {
        if (topicsRc == null) {
            topicsRc = new ArrayList<>();

//            List<Topic> topics1 = new ArrayList<>();
//            List<Topic> topics2 = new ArrayList<>();
//            List<Topic> topics3 = new ArrayList<>();

            List<List<Topic>> mCategoryes = new ArrayList<>();
            for (int i = 0; i < MicrometerTable.getInstance().getCategories(CreateMicrometerTableDailog2.rid).size(); i++) {
                List<Topic> topics1 = new ArrayList<>();
                mCategoryes.add(topics1);
            }

            for (int i = 0; i < richangS.size(); i++) {
                Topic topic = new Topic();
                topic.Copy(MicrometerTable.getInstance().getTopicsAll().get(Integer.valueOf(MicrometerTable.getInstance().richangS.get(i)) - 1));
                topic.setCount((i + 1) + "");

//                for (int j = 0; j < MicrometerTable.getInstance().getCategories(CreateMicrometerTableDailog2.rid).size(); j++) {
//                    if (topic.getCategoryID().trim().equals(MicrometerTable.getInstance().getCategories(CreateMicrometerTableDailog2.rid).get(j).getId().trim())) {
//                        topic.setIndex(topics1.size() + "");
//                        topic.setTitleIndex((j + 1) + "");
//                        topic.setTitle(MicrometerTable.getInstance().getCategories(CreateMicrometerTableDailog2.rid).get(j).getName());
//                        topics1.add(topic);
//                    }
//                }

                for (int j = 0; j < mCategoryes.size(); j++) {
                    if (topic.getCategoryID().trim().equals(MicrometerTable.getInstance().getCategories(CreateMicrometerTableDailog2.rid).get(j).getId().trim())) {
                        topic.setIndex(mCategoryes.get(j).size() + "");
                        topic.setTitleIndex((j + 1) + "");
                        topic.setTitle(MicrometerTable.getInstance().getCategories(CreateMicrometerTableDailog2.rid).get(j).getName());
                        mCategoryes.get(j).add(topic);
                    }
                }

//                if (topic.getCategory().trim().contains("设施环境标准")) {
//                    topic.setIndex(topics1.size() + "");
//                    topic.setTitleIndex("1");
//                    topic.setTitle("设施环境标准");
//                    topics1.add(topic);
//                }
//                if (topic.getCategory().trim().contains("照料服务标准")) {
//                    topic.setIndex(topics2.size() + "");
//                    topic.setTitleIndex("2");
//                    topic.setTitle("照料服务标准");
//                    topics2.add(topic);
//                }
//                if (topic.getCategory().trim().contains("管理标准")) {
//                    topic.setIndex(topics3.size() + "");
//                    topic.setTitleIndex("3");
//                    topic.setTitle("管理标准");
//                    topics3.add(topic);
//                }

            }

//            if (topics1.size() > 0) {
//                topicsRc.addAll(topics1);
//            }
//            if (topics2.size() > 0) {
//                topicsRc.addAll(topics2);
//            }
//            if (topics3.size() > 0) {
//                topicsRc.addAll(topics3);
//            }

            for (int i = 0; i < mCategoryes.size(); i++) {
                topicsRc.addAll(mCategoryes.get(i));
            }

            for (int i = 0; i < topicsRc.size(); i++) {
                topicsRc.get(i).setCount((i + 1) + "");
            }

//            //排除历史整改的题目
//            List<Topic> realTopics = new ArrayList<>();
//
//            for (int i = 0; i < topicsRc.size(); i++) {
//                boolean b = false;//是否为历史整改的题目
//                if (topicsHostoryRC != null && topicsHostoryRC.size() > 0) {
//                    //Log.e("test", "进来了");
//                    for (int j = 0; j < topicsHostoryRC.size(); j++) {
//                        //Log.e("test", "id:\t" + topic.getId().trim() + "\tid:\t" + topicsHostoryQF.get(j).getId().trim());
//                        if (topicsRc.get(i).getId().trim().equals(topicsHostoryRC.get(j).getId().trim())) {
//                            b = true;
//                        }
//                        if (topicsRc.get(i).getQuestion().trim().equals(topicsHostoryRC.get(j).getQuestion().trim())) {
//                            b = true;
//                        }
//                    }
//                }
//                if (!b) {
//                    //日常表里的题目不包含历史整改的题目
//                    realTopics.add(topicsRc.get(i));
//                }
//            }
//
//            if (realTopics.size() > 0) {
//                //日常表表排序
//                String title = "";
//                int titleIndex = 1;//标题下标
//                for (int i = 0; i < realTopics.size(); i++) {
//                    if (i == 0) {
//                        realTopics.get(i).setIndex("0");
//                        realTopics.get(i).setTitleIndex(titleIndex + "");
//                        titleIndex++;
//                        title = realTopics.get(i).getTitle();
//                    } else {
//                        if (title.trim().equals(realTopics.get(i).getTitle().trim())) {
//                            realTopics.get(i).setIndex("1");
//                        } else {
//                            realTopics.get(i).setIndex("0");
//                            realTopics.get(i).setTitleIndex(titleIndex + "");
//                            titleIndex++;
//                            title = realTopics.get(i).getTitle();
//                        }
//                    }
//                }
//            }
//            //筛选过后的日常表数据
//            topicsRc = realTopics;

        }
        return topicsRc;
    }

    //专线表数据标志================================================================================================================================================================================================
    public String getTopicsMarkZhuangXiang() {
        return getTopicsMark(null, null) + "专项表" + CreateMicrometerTableDailog3.jlyName;//千分表标志+专项表敬老院为标志。
    }

    public List<Topic> topicsZX = new ArrayList<>();//专项表数据，直接调用这个。

    //获取专项表
    public void getTopicsZX(String oid, final BaseListenner<Boolean> B) {
        Http.getInstance().getDataZX(oid, B);
    }

    //缓存专项表的数据
    public void saveTOpicsZX() {
        if (topicsZX.size() > 0) {
            CacheUtils.getInstance().put(getTopicsMarkZhuangXiang(), JSONObjectUtils.getInstance().ArrayListToJSON(topicsZX));
        }
    }

    //敬老院数据标志================================================================================================================================================================================================
    public String getJLYMark() {
        return "jinglaoyuang";//千分表标志+专项表敬老院为标志。
    }

    public static List<Jinlaoyuang> jlys = new ArrayList<>();//敬老院

    //获取敬老院
    public List<Jinlaoyuang> getJlys() {
        if (jlys == null || jlys.size() <= 0) {
            Http.getInstance().getJly();
        }
        return jlys;
    }

    //获取指定敬老院ID
    public String getJlyID(String jlyName) {
        String id = "12";
        for (int i = 0; i < getJlys().size(); i++) {
            if (jlyName.equals(getJlys().get(i).getName())) {
                id = getJlys().get(i).getId();
                break;
            }
        }
        return id;
    }

    //根據id獲取指定敬老院名稱
    public String getJlyName(String jlyID) {
        String jlyName = "";
        if(getJlys()!=null&&jlyID!=null){
            for (int i = 0; i < getJlys().size(); i++) {
                if(getJlys().get(i)!=null&&getJlys().get(i).getId()!=null){
                    if (jlyID.trim().equals(getJlys().get(i).getId().trim())) {
                        jlyName = getJlys().get(i).getName();
                        break;
                    }
                }
            }
        }
        return jlyName;
    }

    //溝通人員数据标志================================================================================================================================================================================================
    public String getLinkUPMark() {
        return "linkup";//千分表标志+专项表敬老院为标志。
    }

    public static List<Linkup> linkups = new ArrayList<>();//主要沟通人员

    //获取主要沟通人员
    public List<Linkup> getLinkups() {
        if (linkups == null || linkups.size() <= 0) {
            Http.getInstance().getLinkUP();
        }
        return linkups;
    }

    //获取指定联系人ID
    public String getLinkupID(String linkName) {
        String id = "12";
        for (int i = 0; i < getLinkups().size(); i++) {
            if (linkName.equals(getLinkups().get(i).getName())) {
                id = getLinkups().get(i).getId();
                break;
            }
        }
        return id;
    }

    //题目类型(静安，闸北)数据标志================================================================================================================================================================================================
    public String getTimuTypeMark() {
        return "timutype";
    }

    public static List<TimuType> timuTypes = new ArrayList<>();//主要沟通人员

    //获取题目类型
    public List<TimuType> getTimuTypes() {
        if (timuTypes == null || timuTypes.size() <= 0) {
            Http.getInstance().getTimuTypes();
        }
        return timuTypes;
    }

    //获取题目类型ID
    public String getTimuTypeID(String timuType) {
        String id = "12";
        for (int i = 0; i < getTimuTypes().size(); i++) {
            if (timuType.equals(getTimuTypes().get(i).getQuname())) {
                id = getTimuTypes().get(i).getId();
                break;
            }
        }
        return id;
    }

    //获取题目类别ID
    public String getCategorID(String category, String rid) {
        List<Categories> categories = getCategories(rid);
        String id = "";
        for (int i = 0; i < categories.size(); i++) {
            String name = categories.get(i).getName().trim();
            if (name.trim().equals(category.trim())) {
                id = categories.get(i).getId();
                break;
            }
        }
        return id.trim();
    }

    //巡检信息
    private Qfinfo qfinfo;

    public Qfinfo getQfinfo() {
        return qfinfo;
    }

    public void setQfinfo(Qfinfo qfinfo) {
        this.qfinfo = qfinfo;
    }

}
